using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Beetle.Controller;

public class ActionContext : IDisposable
{
	private static Stack<ActionContext> m_a;

	private IList<FilterAttribute> b;

	private u c;

	private int d = -1;

	[CompilerGenerated]
	private object e;

	[CompilerGenerated]
	private object f;

	[CompilerGenerated]
	private IChannel g;

	public object Result
	{
		[CompilerGenerated]
		get
		{
			return e;
		}
		[CompilerGenerated]
		set
		{
			e = value;
		}
	}

	public object Message
	{
		[CompilerGenerated]
		get
		{
			return f;
		}
		[CompilerGenerated]
		set
		{
			f = value;
		}
	}

	public IChannel Channel
	{
		[CompilerGenerated]
		get
		{
			return g;
		}
		[CompilerGenerated]
		set
		{
			g = value;
		}
	}

	static ActionContext()
	{
		ActionContext.m_a = new Stack<ActionContext>(128);
		for (int i = 0; i < 128; i++)
		{
			ActionContext.m_a.Push(new ActionContext());
		}
	}

	private ActionContext()
	{
	}

	public static ActionContext GetContext()
	{
		lock (ActionContext.m_a)
		{
			if (ActionContext.m_a.Count > 0)
			{
				return ActionContext.m_a.Pop();
			}
			return new ActionContext();
		}
	}

	internal void a(IChannel A_0, object A_1, u A_2)
	{
		d = -1;
		Channel = A_0;
		Message = A_1;
		b = A_2.c;
		c = A_2;
	}

	public void Execute()
	{
		if (b != null && b.Count > 0)
		{
			d++;
			if (d >= b.Count)
			{
				Result = c.e(Channel, Message);
			}
			else
			{
				b[d].Execute(this);
			}
		}
		else
		{
			Result = c.e(Channel, Message);
		}
	}

	public void Dispose()
	{
		lock (ActionContext.m_a)
		{
			ActionContext.m_a.Push(this);
		}
	}
}
